package com.qef.com.mmovie.mvp.interactor;

import com.orhanobut.logger.Logger;
import com.qef.com.mmovie.api.ApiSever;
import com.qef.com.mmovie.api.VideoListBean;
import com.qef.com.mmovie.net.IGetDataDelegate;
import com.qef.com.mmovie.utils.RxUtil;

import javax.inject.Inject;

import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Created by guangjiego on 2017/3/22.
 */

public class VideoInteractor {
    private ApiSever apiSever;

    @Inject
    public VideoInteractor(ApiSever apiSever) {
        this.apiSever = apiSever;
    }

    public Disposable loadPlayList(String data, final IGetDataDelegate<VideoListBean> iGetDataDelegate) {
        return apiSever.getVideoList(data).
                compose(RxUtil.<VideoListBean>background())
                .subscribe(new Consumer<VideoListBean>() {
                               @Override
                               public void accept(@NonNull VideoListBean infoEntity) throws Exception {
                                   iGetDataDelegate.getDataSuccess(infoEntity);
                               }

                           }, new Consumer<Throwable>() {
                               @Override
                               public void accept(@NonNull Throwable throwable) throws Exception {
                                   throwable.printStackTrace();
                                   Logger.i("xxxxxxxxx-----------------");
                                   iGetDataDelegate.getDataError(throwable);
                               }
                           }
                );
    }
}
